<template>
      <el-menu router unique-opened :default-active="currentMenu">
        <el-submenu v-for="item in navList" :key="item.key" :index="item.index">
          <template slot="title"><i :class="item.icon"></i>{{item.title}}</template>
          <el-menu-item v-for="item2 in item.children" :key="item2.key" :index="item2.index" @click="savaNavState(item2.index)">
            <template slot="title"><i :class="item2.icon"></i>{{item2.title}}</template>
          </el-menu-item>
        </el-submenu>
      </el-menu>
</template>

<script>
export default {
  name: "left",
  data() {
    return {
      currentMenu:'',
      navList:[
        {
          title:"用户管理",
          index:"1",
          key:'100',
          icon:'el-icon-user',
          children:[
            {
              title:'用户列表',
              index:'/main/userList',
              key:'101',
              icon:'el-icon-document'
            }
            
          ]
        },
        {
          title:"权限管理",
          index:"2",
          key:'200',
          icon:'el-icon-key',
          children:[
            {
              title:'权限列表',
              index:'/main/roleList',
              key:'201',
              icon:'el-icon-document'
            },
            {
              title:'添加管理人',
              index:'/main/addRoles',
              key:'202',
              icon:'el-icon-document-add'
            }
            
          ]
        },
        {
          title:"商品管理",
          index:"3",
          key:'300',
          icon:'el-icon-goods'
        },
        {
          title:"订单管理",
          index:"4",
          key:'400',
          icon:'el-icon-document-copy'
        },
        {
          title:"数据统计",
          index:"5",
          key:'500',
          icon:'el-icon-coin',
          children:[
            {
              title:'基本数据',
              index:'/main/echarts',
              key:'501',
              icon:'el-icon-pie-chart'
            }
          ]
        }

      ]
    }
  },
  methods:{
    savaNavState(activePath){
      window.sessionStorage.setItem('activePath',activePath);
    }
  },
  created(){
    this.currentMenu=window.sessionStorage.getItem('activePath')
  },
  watch:{
    $route(e){
      this.currentMenu=e.path;
    }
  }

};
</script>

<style scoped>



</style>